{% load i18n %}

{% if parent_for_portlets %}
    <form class="portlets-form"
          action="{% url lfs_update_portlets object_type_id, object.id %}"
          method="post"
          style="padding-bottom:25px">
        <h2>{% trans 'Blocked parent slots' %}</h2>
        {% for slot in slots.items %}
            <div>
                <input type="checkbox"
                       name="block_slot"
                       value="{{ slot.id }}"
                       {% if slot.is_blocked %}checked="checked"{% endif %} />
                <label class="middle">{% trans slot.name %}</label>
            </div>
        {% endfor %}

        <div class="buttons">
            <input type="submit"
                   class="button ajax-save-button"
                   value="{% trans 'Save blocked parent slots' %}" />
        </div>
    </form>
{% endif %}

<h2>{% trans 'Slots' %}</h2>
{% for slot in slots.items %}
    <h3 {% if forloop.first %}class="first-heading"{% endif %}>
        {% trans 'Slot' %}: {% trans slot.name %}
    </h3>

    {% if slot.portlets %}
        <table class="lfs-manage-table">
            <tr>
                <th class="middle">
                    {% trans 'Type' %}
                </th>
                <th>
                    {% trans 'Title' %}
                </th>
                <th class="small right-padding">
                    {% trans 'Manage' %}
                </th>
            </tr>
            {% for portlet in slot.portlets %}
                <tr class="portlet-edit-button"
                    href="{% url lfs_edit_portlet portlet.pa_id %}">
                    <td>
                        {% trans portlet.type %}
                    </td>
                    <td>
                        {{ portlet.title }}
                    </td>
                    <td class="right-padding" nowrap="nowrap">
                        {% if not forloop.first %}
                            <a class="up ajax-link"
                               href="{% url lfs_move_portlet portlet.pa_id %}?direction=0"
                               title='{% trans "Move Up" %}'></a>
                        {% else %}
                            <span class="blank"></span>
                        {% endif %}
                        {% if not forloop.last %}
                            <a class="down ajax-link"
                               href="{% url lfs_move_portlet portlet.pa_id %}?direction=1"
                               title='{% trans "Move Down" %}'></a>
                        {% else %}
                            <span class="blank"></span>
                        {% endif %}
                        <a class="delete-link delete"
                           dialog_yes_button_class="ajax-save-button"
                           dialog_message='{% trans "Do you really want to delete this portlet?" %}'
                           href="{% url lfs_delete_portlet portlet.pa_id %}"
                           title='{% trans "Delete" %}'></a>
                    </td>
                </tr>
            {% endfor %}
        </table>
    {% else %}
        <p class="no-portlets">{% trans 'There are no portlets assigned' %}</p>
    {% endif %}
{% endfor %}

<h2 class="heading-middle">
    {% trans 'Add new portlet' %}
</h2>

<form class="portlet-add-form"
      action="{% url lfs_add_portlet object_type_id, object.id %}"
      method="get">
    <select name="portlet_type">
        {% for portlet_type in portlet_types %}
            <option value="{{ portlet_type.type }}">
                {% trans portlet_type.name %}
            </option>
        {% endfor %}
    </select>

    <input class="button portlet-add-button"
           type="submit"
           value="{% trans 'Add portlet' %}" />
</form>
